import 'package:distribution_mall_flutter/Introduction/Introduction_hone_one.dart';
import 'package:distribution_mall_flutter/Introduction/Introduction_product_sample.dart';
import 'package:distribution_mall_flutter/assets.dart';
import 'package:distribution_mall_flutter/constant/image_constant.dart';
import 'package:distribution_mall_flutter/generated/l10n.dart';
import 'package:distribution_mall_flutter/pages/goods/product_details/application/product_details_service.dart';
import 'package:distribution_mall_flutter/provider/goods/product_details.dart';
import 'package:distribution_mall_flutter/utils/image_loader.dart';
import 'package:distribution_mall_flutter/utils/storage.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

class ProductSample extends ConsumerStatefulWidget {
  final String saleItemId;

  const ProductSample(this.saleItemId, {super.key});

  @override
  ConsumerState<ProductSample> createState() => _ProductSampleState();
}

class _ProductSampleState extends ConsumerState<ProductSample> {
  void getSample() {
    ref
        .read(productDetailsServiceProvider(widget.saleItemId))
        .getSample(context);
  }

  @override
  Widget build(BuildContext context) {
    bool? sample = ref.watch(pDetailProvider).detail?.suInfo?.sample;
    return SliverToBoxAdapter(
      child: sample == true
          ? GestureDetector(
              onTap: () {
                getSample();
              },
              child: Container(
                margin: const EdgeInsets.only(left: 8, right: 8, top: 20),
                padding: const EdgeInsets.all(14),
                decoration: const BoxDecoration(
                    borderRadius: BorderRadius.all(Radius.circular(8)),
                    gradient: LinearGradient(
                        begin: Alignment.topCenter,
                        end: Alignment.bottomCenter,
                        colors: [
                          Color(0xff2f66fc),
                          Color(0xff73b1fb),
                        ],
                        stops: [
                          0,
                          1
                        ])),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        // ImageLoader.imageNet(
                        //   ImageConstant.librengSample,
                        //   isReplace: false,
                        //   width: 144,
                        // ),
                        Image.asset(
                          Assets.assets_icons_libreng_sample_png,
                          width: 144,
                        ),
                        Container(
                          margin: const EdgeInsets.only(top: 3),
                          child: Text(
                            S.current.get_free_sample_sub_title,
                            style: const TextStyle(
                                fontSize: 12, color: Colors.white),
                          ),
                        ),
                      ],
                    ),
                    Container(
                      decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(15),
                      ),
                      width: 70,
                      height: 33,
                      alignment: Alignment.center,
                      child: Text(
                        key: ref
                            .read(productDetailsServiceProvider(
                                widget.saleItemId))
                            .sampleTextKey,
                        S.current.Get,
                        style: const TextStyle(
                            fontSize: 18,
                            fontWeight: FontWeight.w600,
                            color: Color(0xFF007DF9)),
                      ),
                    )
                  ],
                ),
              ),
            )
          : Container(),
    );
  }
}
